package com.hk.config;

import com.hk.intercept.JwtTokenAdminInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * webMvc高级配置
 */
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

    @Autowired
    private JwtTokenAdminInterceptor jwtTokenAdminInterceptor;

    /**
     * 拦截器配置
     *
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(jwtTokenAdminInterceptor) //所需要配置的拦截器
                .addPathPatterns("/**") //需要拦截的路径
                .excludePathPatterns("/login","/captchaImage","/getInfo","/getRouters"); //需要放行的路径
    }

    /**
     * 设置静态资源映射(放行路径)
     *
     * @param registry
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //  swagger配置可访问
        registry.addResourceHandler("/doc.html").
                addResourceLocations("classpath:/META-INF/resources/");
        // cpolar 映射可访问资源
        registry.addResourceHandler("/webjars/**").
                addResourceLocations("classpath:/META-INF/resources/webjars/");
    }
}